Quadratic Equation Package
Copyright 1995 Lunar Engineering
By Ashish Mishra

This package solves binomials using the Quadratic Equation. Roots produced must be real values only.  If a root is complex, the solutions x1, x2 will be set to 0.

ax^2 + bx + c

aq_value: a value
bq_value: b value
cq_value: c value

Note the variable names are simply not a, b, and c.  This is because Lunar MathStar uses a search and replace technique for solving equations.  Therefore, variable names have to be completely unique.  (ie. if a=5 and you have an equation "bad*2", MathStar will replace the letter "a" by it's value and try to solve "b5d*2" and thus produce an error!)

Note also we did not use a_value, b_value, c_value.  Do you know why?  Anything with a "c_" in it is treated as a constant - and will not be displayed in the show variables unless the constants screen is turned on.  (thus after making this error ourselves, we changed the names!)

The following is the actual equation file for this package.  Note that the special functions: Pow (x, 2) is equivalent to x^2 (which NewtonScript does not handle) and
Sqrt(x) which returns the square root of x.

Note also the small amount of NewtonScript programming done to solve for x1_value and x2_value.  This little procedure ensures that the roots you solve for are real - and if they aren't, it returns a 0 value.

Variable: aq_value (units)
Type: CNST
Equations:
(-cq_value-bq_value*x1_value)/Pow(x1_value, 2) (-cq_value-bq_value*x2_value)/Pow(x2_value,2)

Variable: bq_value (units)
Type: CNST
Equations:
-(cq_value+aq_value*Pow(x1_value, 2))/x1_value
-(cq_value+aq_value*Pow(x2_value, 2))/x2_value

Variable: cq_value (units)
Type: CNST
Equations:
-bq_value-aq_value*Pow(x1_value, 2)
-bq_value-aq_value*Pow(x2_value, 2)

Variable: x1_value (units)
Type: CNST
Equation:
if (Pow(bq_value,2)-4*aq_value*cq_value)>= 0 then return (-bq_value+Sqrt( Pow(bq_value,2)-4*aq_value*cq_value))/(2*aq_value) else return 0
 

Variable: x2_value (units)
Type: CNST
Equation:
if (Pow(bq_value,2)-4*aq_value*cq_value)>= 0 then return (-bq_value-Sqrt( Pow(bq_value,2)-4*aq_value*cq_value))/(2*aq_value) else return 0"]], 
